<?php

/*
 * Action 3$
 *
 * +1 Buy
 * Discard any number of cards. +1 Card per card discarded.
 * Discard any number of cards. +1 Coin per card discarded the second time.
 * 
 */

class Storeroom extends Card implements iAction, iKingdom, iDarkAges {

    public function __construct() {
        parent::__construct("Storeroom", 3);
        $this->undoPlay = false;
        $this->undoBuy = true;
    }

    public function getDescription() {
        return array(
            "+1 Buy",
            "Discard any number of cards. +1 Card per card discarded.",
            "Discard any number of cards. +1 Coin per card discarded the second time.");
    }

    public function play(Game $game, $isRealCard) {
        $game->addBuys(1);
        ScreenDisplay::addScreenMessage($game, true, "get +1 buy", "gets +1 buy");

        $cards = $game->getPlayHand();
        if (sizeof($cards) > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 0, -1, null, "Choose cards to discard");


            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($output), "discards " . sizeof($output) . " cards");
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }

            $drawed_cards = $game->drawCards(sizeof($output));
            ScreenDisplay::addScreenMessage($game, false, " and draw  " . nicePrint($drawed_cards), " and draws " . sizeof($drawed_cards) . " cards");
        }

        $cards = $game->getPlayHand();
        if (sizeof($cards) > 0) {

            $output = MySocket::GetUserReply($game, Input_ChooseMany, $cards, 0, -1, null, "Choose cards to discard for coins");

            $coins = sizeof($output);
            foreach ($output as $p) {
                $game->moveCardFromPileToPile($p, PlayHand, DiscardPile);
            }
            $game->addMoney(new Price($coins));
            ScreenDisplay::addScreenMessage($game, true, "discard  " . nicePrint($output) . " and get +$coins$", "discards " . sizeof($output) . " cards and gets +$coins$");
        }
		$game->cardActionFinished();
        return true;
    }

}

?>